// 第二题 字母异位词
#include<iostream>
#include<vector>
#include<string>
#include<unordered_map>
#include<algorithm>

using namespace std;


class Solution{

public:
    vector<vector<string>> groupAnagrams(vector<string>& strs){
        unordered_map<string, vector<string>> anagramGroups;
        
        
        // 创建一个哈希表，用于存储字母异位词
        
        for (const string& str : strs){
            string sortedStr = str;
            sort(sortedStr.begin(), sortedStr.end());
            anagramGroups[sortedStr].push_back(str);
        }        
        
        vector<vector<string>> result;

        for(const auto& pair : anagramGroups){
            result.push_back(pair.second);
        }

        return result;


    }

};

int Print(vector<vector<string>> a){
    for(int i=0; i < a.size(); i++){
        for(const string s : a[i]){
            cout << s << " ";
        }
        cout << endl;
    }
    return 0;
}


int main(){

    vector<string> strs = {"eat", "ate", "tae", "tan", "atn", "bat"};

    Solution solution;
    vector<vector<string>> result = solution.groupAnagrams(strs); 
    Print(result);
    return 0;
}





